package com.hewang.helloandroid;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.hewang.helloandroid.learnwebview.WebviewJsActivity;
import com.hewang.helloandroid.listview.ListViewActivity;
import com.hewang.helloandroid.recyclerview.RecyclerViewActivity;
import com.hewang.thread.ThreadTestActivity;

public class MainActivity extends AppCompatActivity {

    private Button mBtnTextView;
    private Button mBtnLinearLayout;
    private Button mBtnRelativeLayout;
    private Button mBtnButton;
    private Button mBtnEditText;
    private Button mBtnBroadcast;
    private Button mBtnWebviewTest;
    private Button mBtnHttpUrlConnection;
    private Button mBtnOkHttp;
    private Button mBtnRadioButton;
    private Button mBtnCheckBox;
    private Button mBtnImageView;
    private Button mBtnListView;
    private Button mBtnRecyclerView;
    private Button mBtnWebviewJs;
    private Button mBtnCameraAlbum;
    private Button mBtnCameraPreview;
    private Button mBtnCamera2Preview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); // 定义Activity界面的布局
        // 线性布局
        mBtnRelativeLayout = findViewById((R.id.btn_linearlayout));
        addOnClickById(mBtnRelativeLayout, LinearLayout.class);
        // 相对布局
        mBtnLinearLayout = findViewById((R.id.btn_relativeLayout));
        addOnClickById(mBtnLinearLayout, RelativeLayout.class);
        // 文本
        mBtnTextView = findViewById(R.id.btn_textview);
        addOnClickById(mBtnTextView, TextViewActivity.class);
        // 按钮
        mBtnButton = findViewById(R.id.btn_button);
        addOnClickById(mBtnButton, ButtonActivity.class);

        // 单选框
        mBtnRadioButton = findViewById(R.id.btn_radio_btn);
        addOnClickById(mBtnRadioButton, RadioButtonActivity.class);

        // 复选框
        mBtnCheckBox = findViewById(R.id.btn_check_box);
        addOnClickById(mBtnCheckBox, CheckBoxActivity.class);

        // editText
        mBtnEditText = (Button)findViewById(R.id.btn_editText);
        addOnClickById(mBtnEditText, EditTextActivity.class);

        // ImageView
        mBtnImageView = findViewById(R.id.btn_imageView);
        addOnClickById(mBtnImageView, ImageViewActivity.class);

        // ListView
        mBtnListView = findViewById(R.id.btn_listView);
        addOnClickById(mBtnListView, ListViewActivity.class);

        // RecyclerView
        mBtnRecyclerView = findViewById(R.id.btn_recycler_view);
        addOnClickById(mBtnListView, RecyclerViewActivity.class);

        addOnClickById(findViewById(R.id.btn_loading_view), Loading.class);

        // 广播
        mBtnBroadcast = (Button)findViewById(R.id.btn_broadcast);
        addOnClickById(mBtnBroadcast, BroadcastTestActivity.class);
        // WebView测试
        mBtnWebviewTest = (Button)findViewById(R.id.btn_webviewtest);
        addOnClickById(mBtnWebviewTest, WebviewTestActivity.class);

        // WebView与js的交互
        mBtnWebviewJs = findViewById(R.id.btn_webview_js);
        addOnClickById(mBtnWebviewJs, WebviewJsActivity.class);
//        addOnClickById();
        // http请求测试
        mBtnHttpUrlConnection = (Button) findViewById(R.id.btn_httpurlconnection);
        addOnClickById(mBtnHttpUrlConnection, HttpURLActivity.class);

        // mBtnOkHttp
        mBtnOkHttp = (Button) findViewById(R.id.btn_okhttp);
        addOnClickById(mBtnOkHttp, OkHttpActivity.class);
//        调用相机应用拍照
        mBtnCameraAlbum = (Button)findViewById(R.id.btn_camera_album);
        addOnClickById(mBtnCameraAlbum, CameraAlbumActivity.class);
        // 调用摄像头预览
        mBtnCameraPreview = (Button)findViewById(R.id.btn_camera_preview);
        addOnClickById(mBtnCameraPreview, OpenCameraView.class);

        // 调用摄像头预览Camera2
        mBtnCamera2Preview = findViewById(R.id.btn_camera2_preview);
        addOnClickById(mBtnCamera2Preview, Camera2Preview.class);

        // 线程测试
        addOnClickById(findViewById(R.id.btn_thread_test), ThreadTestActivity.class);

    }

    public void addOnClickById(Button button, Class<?> cls) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, cls);
                startActivity(intent);
            }
        });
    }
}